<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Constructs a mysqli_result object</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.mysqli-result.html">« mysqli_result</a></li>
      <li style="float: right;"><a href="mysqli-result.current-field.html">mysqli_result::$current_field »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mysqli-result.html">mysqli_result</a></li>
    <li>Constructs a mysqli_result object</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mysqli-result.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqli_result::__construct</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mysqli_result::__construct</span> &mdash; <span class="dc-title">Constructs a <span class="classname"><a href="class.mysqli-result.html" class="classname">mysqli_result</a></span> object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysqli-result.construct-description">
  <h3 class="title">说明</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>mysqli_result::__construct</strong></span>(<span class="methodparam"><span class="type"><a href="class.mysqli.html" class="type mysqli">mysqli</a></span> <code class="parameter">$mysql</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$result_mode</code><span class="initializer"> = <strong><code>MYSQLI_STORE_RESULT</code></strong></span></span>)</div>

  <p class="para rdfs-comment">
   This method constructs a new <span class="classname"><a href="class.mysqli-result.html" class="classname">mysqli_result</a></span> object.
  </p>
  <p class="para">
   It can be used to create the <span class="classname"><a href="class.mysqli-result.html" class="classname">mysqli_result</a></span> object
   after calling the <span class="function"><a href="mysqli.real-query.html" class="function">mysqli_real_query()</a></span> or
   <span class="function"><a href="mysqli.multi-query.html" class="function">mysqli_multi_query()</a></span> function. Constructing the object
   manually is equivalent to calling the <span class="function"><a href="mysqli.store-result.html" class="function">mysqli_store_result()</a></span>
   or <span class="function"><a href="mysqli.use-result.html" class="function">mysqli_use_result()</a></span> function.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mysqli-result.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>
   <dt>

<code class="parameter">mysql</code></dt>
<dd>
<p class="para">仅以过程化样式：由<span class="function"><a href="function.mysqli-connect.html" class="function">mysqli_connect()</a></span> 或 <span class="function"><a href="mysqli.init.html" class="function">mysqli_init()</a></span>
返回的 <span class="classname"><a href="class.mysqli.html" class="classname">mysqli</a></span> 对象。</p></dd>

   
    <dt>
<code class="parameter">result_mode</code></dt>

    <dd>

     <p class="para">
      The result mode can be one of 2 constants indicating how the result will
      be returned from the MySQL server.
     </p>
     <p class="para">
      <strong><code>MYSQLI_STORE_RESULT</code></strong> (default) - creates a
      <span class="classname"><a href="class.mysqli-result.html" class="classname">mysqli_result</a></span> object with buffered result set.
     </p>
     <p class="para">
      <strong><code>MYSQLI_USE_RESULT</code></strong> - creates a
      <span class="classname"><a href="class.mysqli-result.html" class="classname">mysqli_result</a></span> object with unbuffered result set. 
      As long as there are pending records waiting to be fetched, the
      connection line will be busy and all subsequent calls will return error 
      <code class="literal">Commands out of sync</code>. To avoid the error all records 
      must be fetched from the server or the result set must be discarded by
      calling <span class="function"><a href="mysqli-result.free.html" class="function">mysqli_free_result()</a></span>. The connection must
      remain open for the rows to be fetched.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 examples" id="refsect1-mysqli-result.construct-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1515">
   <p><strong>示例 #1 Creation of a <span class="classname"><a href="class.mysqli-result.html" class="classname">mysqli_result</a></span> object</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />mysqli_report</span><span style="color: #007700">(</span><span style="color: #0000BB">MYSQLI_REPORT_ERROR&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">MYSQLI_REPORT_STRICT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"world"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Select&nbsp;queries&nbsp;return&nbsp;a&nbsp;result&nbsp;set&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">real_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;Name&nbsp;FROM&nbsp;City&nbsp;LIMIT&nbsp;10"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Select&nbsp;returned&nbsp;%d&nbsp;rows.\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">num_rows</span><span style="color: #007700">);</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Select returned 10 rows.
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mysqli-result.construct-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mysqli.multi-query.html" class="function" rel="rdfs-seeAlso">mysqli_multi_query()</a> - 执行查询</span></li>
    <li class="member"><span class="function"><a href="mysqli.real-query.html" class="function" rel="rdfs-seeAlso">mysqli_real_query()</a> - 执行一个mysql查询</span></li>
    <li class="member"><span class="function"><a href="mysqli.store-result.html" class="function" rel="rdfs-seeAlso">mysqli_store_result()</a> - 转移上一次查询返回的结果集</span></li>
    <li class="member"><span class="function"><a href="mysqli.use-result.html" class="function" rel="rdfs-seeAlso">mysqli_use_result()</a> - Initiate a result set retrieval</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>